/* 指向类成员（成员变量和成员方法）的指针
 *
 * */
#include <iostream>
using namespace std;
class Test{
public:
    void func(){
        cout<<"func"<<endl;
    }
    static void static_func(){
        cout<<"static_func"<<endl;
    }
    int ma;
    static int mb;
};
int Test::mb;

int main(){
    Test t1;
    Test *t2=new Test();

    //指向成员方法的指针
    void (Test::*pfunc)()=&Test::func;
    (t1.*pfunc)();
    (t2->*pfunc)();

    /*指向成员变量的指针
    //int *p=&Test::ma;           // 报错，右边类型是 int Test::*

    int Test::*q=&Test::ma;

    t1.*q=2;
    cout<<t1.ma<<endl;      //输出2

    t2->*q=3;
    cout<<t2->ma<<endl;     //输出3

    int* p1=&Test::mb;
    *p1=4;
    cout<<Test::mb<<endl;   //输出4

     */

    delete t2;

    return 0;
}